/*************************************************************************
	> File Name: P1060.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2024-12-23 14:59:58
 ************************************************************************/

#include <iostream>
using namespace std;

#define MAX_N 30000

int dp[MAX_N + 5];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1, val, p; i <= m; i++) {
        cin >> val >> p;
        for (int j = n; j >= val; j--) {
            dp[j] = max(dp[j], dp[j - val] + val * p);
        }
    }
    cout << dp[n] << endl;
    return 0;
}
